[#include "/WEB-INF/pages/common/taglibs.ftl"]
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		<link rel="stylesheet" href="[@c.url value='/js/plugins/jquery-ztree/css/zTreeStyle/zTreeStyle.css'/]" type="text/css">
		<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/jquery-ztree/js/jquery.ztree.core-3.1.js'/]"></script>
		
		<style type="text/css">
			.menu {
				padding:0;
				margain:0;
			}
			.menu_tree {
				width:240px;
				/*height:500px;*/
				float:left;
				margin-left:2px;
			}
			.menu_list {
				/*height:500px;*/
				margin-left:248px;
			}
		</style>
		<script type="text/javascript">
			var base = (function(){
				// 事件绑定
				function _addEventListeners() {
					// 一览
					// 删除所选
					$('a.delete').click(function(){
						var tb = jQuery(this).attr('tableid');	
						var sel = false;											//initialize to false as no selected row
						var ch = jQuery('#'+tb).find('tbody input[type=checkbox]');	//get each checkbox in a table
						var content = "功能删除后将无法恢复,是否仍要删除?";
						var title = "删除所选功能";
						jConfirm(content, title, function(r) {
							if (r) {
								// 这里存在问题,form没有被提交
								var _$form = $('<form action="[@c.url value="/manage/Menu_rm.action"/]" method="post"></form>');
								alert(_$form.html());
								var index = 0;
								ch.each(function(){
									if(jQuery(this).is(':checked')) {
										sel = true;	
										var id = $(this).val();
										$(this).parents('tr').fadeOut(function(){
											$(this).remove();							//remove row when animation is finished
										});
										_$form.append("<input type='hidden' name='menuList["+index+"].id' value="+id+" />");
										index ++;
									}
								});
								if (sel) {
									alert(_$form.html());
									_$form.submit();
								} else {
									jAlert('No data selected');
								}
							}
						});
					});
				}
				function _permissionHandler(id, e) {
					//var _$role = $('#roleList');
                	if (!e) {
                		var rolePie = "<div id='roleListDown' style='display:none;'><ul>";
                		$.get("[@c.url value='/manage/Menu_permission.action'/]", {id:id, ajax:true}, function(data){
                			var obj = eval('(' + data + ')');
                			$.each(obj.items, function(i,item){
								//$("<img/>").attr("src", item.media.m).appendTo("#images");
							    rolePie += "<li><input type='checkbox' name='roleList["+ i +"].id'" + (item.isPermission=='true'? "checked='checked'" : "") + "  value='"+item.id+"'/> <label for=''>"+item.title+"</label></li>";  
							});
                			rolePie += "</ul></div>";
                			//jAlert(rolePie);
                			$('#roleList').html(rolePie);
                			$('#roleListDown').slideDown("slow");
                			
                			return false;
						});
                	} else {
                		$('#roleList').empty();
                	}
				}
				return {
	                config: {
	                	url : null,
	                    theme: null
	                },
	                init: function () {
	                	_addEventListeners();
	                	//alert()
	                	_permissionHandler('${id}', ($('#isAnonymous:checked').length>0));
	                },
	                permission: function(id, e){
	                	_permissionHandler(id, e);
	                }
				}
			}());
			
			$(function(){
				var link = "[@c.url value='/manage/Menu_list.action?currentPage=${currentPage}'/]";
				base.config.theme = getTheme();
				base.config.url = link;
	            //Initializing the form
				base.init();
			})
		</script>
	</head>
	<body id="body" class="art_content">
		[#assign act="save"]
		[#include "/WEB-INF/pages/manage/Menu/_menu.ftl"]
	</body>
</html>
